package com.cljz.makepassenger.model.dao;


import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema;

/**
 * Created by apple on 2017/4/5.
 */

public class DaoExample {
    public static void main(String[] args) throws Exception {
        //每次升级必须修改version
        int version = 2;
        String defaultPackage = "com.clzj.makepassenger.bean";
        //创建模式对象，指定版本号和自动生成的bean对象的包名
        Schema schema = new Schema(version, defaultPackage);

        //指定自动生成的dao对象的包名,不指定则都DAO类生成在defaultPackage包中
        schema.setDefaultJavaPackageDao("com.clzj.makepassenger.dao");

        addNote(schema);

        //自动生成的bean和dao存放的java-gen路径，注意要改成自己的
        String outDir = "././app/src/main/java-gen";
        new DaoGenerator().generateAll(schema, outDir);
    }

    private static void addNote(Schema schema) {
        Entity userInfo = schema.addEntity("UserInfo");
        userInfo.addStringProperty("user_logo");
        userInfo.addStringProperty("user_nickname");
        userInfo.addStringProperty("token").notNull().primaryKey();
        userInfo.addStringProperty("birthday");
        userInfo.addStringProperty("user_sex");
        userInfo.addStringProperty("eid").notNull();
        userInfo.addStringProperty("user_phone").notNull();
        userInfo.addStringProperty("age");
        userInfo.addStringProperty("payment_password");
        userInfo.addStringProperty("user_name");
        userInfo.addStringProperty("alipay");
        userInfo.addStringProperty("user_points");
        userInfo.addStringProperty("ratio");

        Entity nearbySearchHistory = schema.addEntity("NearbySearchHistory");
        nearbySearchHistory.addStringProperty("history").notNull().primaryKey();
        nearbySearchHistory.addStringProperty("token").notNull();
        nearbySearchHistory.addLongProperty("add_time").notNull();
    }
}
